import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { GTextFormat } from "../../../../common/GTextFormat";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { TToplist } from "../../../../../Message/Db/Tables/TToplist";
import { AvatarInfo } from "../../../resource/info/AvatarInfo";
import { AvatarType } from "../../../resource/info/AvatarType";
import { ProxyConfig } from "../../../resource/ProxyConfig";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class InterFlowerRenderer
    
    export  class InterFlowerRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            this._itemBg = this.createBitmap(0, 0);
            this._headBg = this.createBitmap(3, 3);
            this._headIcon = this.createBitmap(0, 0);
            this._heartIcon = this.createBitmap(93, 3);
            this._numBottom = this.createBitmap(165, 23);
            this._rankIcon = this.createBitmap(105, 23);
            this._headImg = this.createBitmap(15, 15);
            var loc1=new GTextFormat("", 12, 16749973, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            var loc2=new GTextFormat("", 12, 15788607, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._charmTxt = ObjCreate.createTextField("", 185, 27, 50, 20, this, loc2);
            this._ownerTxt = ObjCreate.createTextField("", 85, 50, 90, 20, this, loc2);
            this._nameTxt = ObjCreate.createTextField("", 85, 70, 90, 20, this, loc1);
            this._giveBtn = ObjCreate.createGButton(Language.getString(36177), 175, 56, 71, 26, this, "ButtonPinkStyle");
            this._giveBtn.drawNow();
            this._giveBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGiveBtnClickHandler);
            LoaderHelp.addResCallBack(ResFileConst.InterFlowerRank, this.onResLoaded);
            return;
        }

        /* internal  */createBitmap(arg1: int, arg2: int): Object /* flash.display.Bitmap */
        {
            var loc1=null;
            loc1 = new Object /* flash.display.Bitmap */();
            loc1.x = arg1;
            loc1.y = arg2;
            addChild(loc1);
            return loc1;
        }

        /* internal  */onResLoaded(): void
        {
            this._itemBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.RankBottom);
            this._headBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.HeadBorder);
            this._heartIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.FlowerHeart);
            this._numBottom.bitmapData = GlobalClass.getBitmapData(ImagesConst.FlowerNumBottom);
            return;
        }

        /* internal  */onResDataLoaded(): void
        {
            this._rankIcon.bitmapData = GlobalClass.getBitmapData("FlowerNo_" + this._toplist.rank);
            if (this._toplist.rank <= 3) 
            {
                this._headIcon.bitmapData = GlobalClass.getBitmapData("HeadNo_" + this._toplist.rank);
            }
            else 
            {
                this._headIcon.bitmapData = null;
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (arg1) 
            {
                this._toplist = arg1 as TToplist;
                AvatarInfo.getAvatar(this._toplist.propertyOne, this._toplist.propertyTwo, AvatarType.BIG, this.onAvatarLoaded, this._toplist.reverse1);
                this._charmTxt.htmlText = this._toplist.valueOne + "";
                this._ownerTxt.htmlText = ProxyConfig.instance.getProxyName(this._toplist.proxyId) + " . " + this._toplist.serverId + Language.getString(36178);
                this._nameTxt.htmlText = this._toplist.entityName;
                LoaderHelp.addResCallBack(ResFileConst.InterFlowerRank, this.onResDataLoaded);
                this.onResLoaded();
            }
            else 
            {
                this._toplist = null;
                this._headImg.bitmapData = null;
                this._charmTxt.htmlText = "";
                this._ownerTxt.htmlText = "";
                this._nameTxt.htmlText = "";
                this._rankIcon.bitmapData = null;
                this._headIcon.bitmapData = null;
                this._itemBg.bitmapData = null;
                this._headBg.bitmapData = null;
                this._heartIcon.bitmapData = null;
                this._numBottom.bitmapData = null;
            }
            return;
        }

        /* internal  */onAvatarLoaded(arg1: ImageInfo): void
        {
            this._headImg.bitmapData = arg1.bitmapData;
            return;
        }

        public resetItem(): void
        {
            this._itemBg.bitmapData = null;
            this._headIcon.x = -9;
            this._headIcon.y = -8;
            return;
        }

        /* internal  */onGiveBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._toplist && !(Cache.instance.ranking.serverId == this._toplist.serverId)) 
            {
                MsgManager.showRollTipsMsg(Language.getString(36179));
            }
            else if (this._toplist) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FlowerOpenHandselFlower, this._toplist.entityName));
            }
            return;
        }

        /* internal */ /* var */_headImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_charmTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_ownerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_giveBtn: GButton;

        /* internal */ /* var */_toplist: TToplist;

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_headBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_headIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_heartIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_numBottom: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rankIcon: Object /* flash.display.Bitmap */;
    }
